package com.cbgolf.oa.activity.closepark;

import android.os.Bundle;
import com.cbgolf.oa.R;
import com.cbgolf.oa.activity.BaseNewActivity;
import com.cbgolf.oa.contract.ICloseParkContract;
import com.cbgolf.oa.entity.Beans;
import com.cbgolf.oa.event.Events;
import com.cbgolf.oa.manager.DataManager;
import com.cbgolf.oa.presenter.CloseParkPresenterImpl;
import com.cbgolf.oa.util.DataUtil;
import com.cbgolf.oa.util.EnumUtil;
import com.cbgolf.oa.util.Util;
import com.cbgolf.oa.views.AddCloseParkViewImp;
import org.greenrobot.eventbus.EventBus;
import org.greenrobot.eventbus.Subscribe;
import org.greenrobot.eventbus.ThreadMode;

/**
 * @author lq
 */
public class CloseParkActivity extends BaseNewActivity implements ICloseParkContract.Waiter {

  private ICloseParkContract.View view;
  private ICloseParkContract.Presenter presenter;

  private int mType;
  private Beans mData;

  @Override
  protected int getLayoutId() {
    return R.layout.a_add_close_park;

  }

  @Override
  protected void init(Bundle savedInstanceState) {
    EventBus.getDefault().register(this);
    mType = DataUtil.getIntExtra(getIntent(), DataManager.KEY_TYPE, 0);
    mData = DataUtil.getSerializableExtra(getIntent(), DataManager.KEY_DATA);
    view = new AddCloseParkViewImp(this, this, mType, mData);
    presenter = new CloseParkPresenterImpl();
    presenter.init(view);

  }

  @Override
  protected void onDestroy() {
    super.onDestroy();
    EventBus.getDefault().unregister(this);
  }

  @Subscribe(threadMode = ThreadMode.MAIN)
  public void requestOver(Events events) {
    view.requestOver(events);
  }

  @Override
  public String getActivityTitle() {
    String title = "封场";
    switch (mType) {
      case EnumUtil.CLOSE_PARK_SHOW_DETAILS:
        title = "封场详情";
        break;
      case EnumUtil.CLOSE_PARK_ADD_NEW:
        title = "新增封场";
        break;
      default:
        break;
    }
    return title;
  }

  @Override
  public void back() {
    finish();
  }


  @Override
  public void addClosePark(Beans beans) {
    presenter.addClosePark(beans);
  }

  @Override
  public void cancelClosePark(String id) {
    presenter.cancelClosePark(id);
  }

  @Override
  public void cancelSuccess() {
    Util.show("取消成功");
    back();
  }

  @Override
  public void addSuccess() {
    Util.show("保存成功");
    back();
  }


}
